package backTrack;

import java.util.*;

public class ds491 {
    public static void main(String[] args) {
        System.out.println(findSubsequences(new int[]{6,6,7,6,6}));
    }
    public static List<List<Integer>> findSubsequences(int[] nums) {
        List<List<Integer>> ans = new ArrayList<>();
        List<Integer> path = new ArrayList<>();
        dfs(nums, ans, path, 0);
        return ans;
    }
    public static void dfs(int[] nums, List<List<Integer>> ans, List<Integer> path, int index){
        if(index > nums.length)
            return;
        if(path.size() >= 2){
            ans.add(new ArrayList<>(path));
        }
        Set<Integer> set = new HashSet<>();
        for (int i = index; i < nums.length; i++) {
            if(!set.add(nums[i]))
                continue;
            if(path.size() != 0){
                int temp = path.get(path.size() - 1);
                if(temp <= nums[i]){
                    path.add(nums[i]);
                    dfs(nums, ans, path, i + 1);
                    path.remove(path.size() - 1);

                }
            }
            else {
                path.add(nums[i]);
                dfs(nums, ans, path, i + 1);
                path.remove(path.size() - 1);
            }
        }
    }
}
